package model

import (
	"fmt"
	"gorm.io/gorm"
	"time"
)

type _WkbCustomerServiceGroupMgr struct {
	*_BaseMgr
}

// WkbCustomerServiceGroupMgr open func
func WkbCustomerServiceGroupMgr(db *gorm.DB) *_WkbCustomerServiceGroupMgr {
	if db == nil {
		panic(fmt.Errorf("WkbCustomerServiceGroupMgr need init by db"))
	}
	ctx, cancel := context.WithCancel(context.Background())
	return &_WkbCustomerServiceGroupMgr{_BaseMgr: &_BaseMgr{DB: db.Table("wkb_customer_service_group"), isRelated: globalIsRelated, ctx: ctx, cancel: cancel, timeout: -1}}
}

// GetTableName get sql table name.获取数据库名字
func (obj *_WkbCustomerServiceGroupMgr) GetTableName() string {
	return "wkb_customer_service_group"
}

// Get 获取
func (obj *_WkbCustomerServiceGroupMgr) Get() (result WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Find(&result).Error

	return
}

// Gets 获取批量结果
func (obj *_WkbCustomerServiceGroupMgr) Gets() (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Find(&results).Error

	return
}

//////////////////////////option case ////////////////////////////////////////////

// WithID id获取 自增id
func (obj *_WkbCustomerServiceGroupMgr) WithID(id int) Option {
	return optionFunc(func(o *options) { o.query["id"] = id })
}

// WithAuthID auth_id获取 wkb_realname_auth的主键id
func (obj *_WkbCustomerServiceGroupMgr) WithAuthID(authID int) Option {
	return optionFunc(func(o *options) { o.query["auth_id"] = authID })
}

// WithCustomerID customer_id获取 对于客服表主键
func (obj *_WkbCustomerServiceGroupMgr) WithCustomerID(customerID int) Option {
	return optionFunc(func(o *options) { o.query["customer_id"] = customerID })
}

// WithGroupID group_id获取 所在技能组id
func (obj *_WkbCustomerServiceGroupMgr) WithGroupID(groupID int) Option {
	return optionFunc(func(o *options) { o.query["group_id"] = groupID })
}

// WithDeleted deleted获取 是否删除:1=是，2=否
func (obj *_WkbCustomerServiceGroupMgr) WithDeleted(deleted int8) Option {
	return optionFunc(func(o *options) { o.query["deleted"] = deleted })
}

// WithUpdatedAt updated_at获取 更新时间
func (obj *_WkbCustomerServiceGroupMgr) WithUpdatedAt(updatedAt time.Time) Option {
	return optionFunc(func(o *options) { o.query["updated_at"] = updatedAt })
}

// WithCreatedAt created_at获取 创建时间
func (obj *_WkbCustomerServiceGroupMgr) WithCreatedAt(createdAt time.Time) Option {
	return optionFunc(func(o *options) { o.query["created_at"] = createdAt })
}

// GetByOption 功能选项模式获取
func (obj *_WkbCustomerServiceGroupMgr) GetByOption(opts ...Option) (result WkbCustomerServiceGroup, err error) {
	options := options{
		query: make(map[string]interface{}, len(opts)),
	}
	for _, o := range opts {
		o.apply(&options)
	}

	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where(options.query).Find(&result).Error

	return
}

// GetByOptions 批量功能选项模式获取
func (obj *_WkbCustomerServiceGroupMgr) GetByOptions(opts ...Option) (results []*WkbCustomerServiceGroup, err error) {
	options := options{
		query: make(map[string]interface{}, len(opts)),
	}
	for _, o := range opts {
		o.apply(&options)
	}

	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where(options.query).Find(&results).Error

	return
}

//////////////////////////enume case ////////////////////////////////////////////

// GetFromID 通过id获取内容 自增id
func (obj *_WkbCustomerServiceGroupMgr) GetFromID(id int) (result WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("id = ?", id).Find(&result).Error

	return
}

// GetBatchFromID 批量唯一主键查找 自增id
func (obj *_WkbCustomerServiceGroupMgr) GetBatchFromID(ids []int) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("id IN (?)", ids).Find(&results).Error

	return
}

// GetFromAuthID 通过auth_id获取内容 wkb_realname_auth的主键id
func (obj *_WkbCustomerServiceGroupMgr) GetFromAuthID(authID int) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("auth_id = ?", authID).Find(&results).Error

	return
}

// GetBatchFromAuthID 批量唯一主键查找 wkb_realname_auth的主键id
func (obj *_WkbCustomerServiceGroupMgr) GetBatchFromAuthID(authIDs []int) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("auth_id IN (?)", authIDs).Find(&results).Error

	return
}

// GetFromCustomerID 通过customer_id获取内容 对于客服表主键
func (obj *_WkbCustomerServiceGroupMgr) GetFromCustomerID(customerID int) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("customer_id = ?", customerID).Find(&results).Error

	return
}

// GetBatchFromCustomerID 批量唯一主键查找 对于客服表主键
func (obj *_WkbCustomerServiceGroupMgr) GetBatchFromCustomerID(customerIDs []int) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("customer_id IN (?)", customerIDs).Find(&results).Error

	return
}

// GetFromGroupID 通过group_id获取内容 所在技能组id
func (obj *_WkbCustomerServiceGroupMgr) GetFromGroupID(groupID int) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("group_id = ?", groupID).Find(&results).Error

	return
}

// GetBatchFromGroupID 批量唯一主键查找 所在技能组id
func (obj *_WkbCustomerServiceGroupMgr) GetBatchFromGroupID(groupIDs []int) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("group_id IN (?)", groupIDs).Find(&results).Error

	return
}

// GetFromDeleted 通过deleted获取内容 是否删除:1=是，2=否
func (obj *_WkbCustomerServiceGroupMgr) GetFromDeleted(deleted int8) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("deleted = ?", deleted).Find(&results).Error

	return
}

// GetBatchFromDeleted 批量唯一主键查找 是否删除:1=是，2=否
func (obj *_WkbCustomerServiceGroupMgr) GetBatchFromDeleted(deleteds []int8) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("deleted IN (?)", deleteds).Find(&results).Error

	return
}

// GetFromUpdatedAt 通过updated_at获取内容 更新时间
func (obj *_WkbCustomerServiceGroupMgr) GetFromUpdatedAt(updatedAt time.Time) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("updated_at = ?", updatedAt).Find(&results).Error

	return
}

// GetBatchFromUpdatedAt 批量唯一主键查找 更新时间
func (obj *_WkbCustomerServiceGroupMgr) GetBatchFromUpdatedAt(updatedAts []time.Time) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("updated_at IN (?)", updatedAts).Find(&results).Error

	return
}

// GetFromCreatedAt 通过created_at获取内容 创建时间
func (obj *_WkbCustomerServiceGroupMgr) GetFromCreatedAt(createdAt time.Time) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("created_at = ?", createdAt).Find(&results).Error

	return
}

// GetBatchFromCreatedAt 批量唯一主键查找 创建时间
func (obj *_WkbCustomerServiceGroupMgr) GetBatchFromCreatedAt(createdAts []time.Time) (results []*WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("created_at IN (?)", createdAts).Find(&results).Error

	return
}

//////////////////////////primary index case ////////////////////////////////////////////

// FetchByPrimaryKey primay or index 获取唯一内容
func (obj *_WkbCustomerServiceGroupMgr) FetchByPrimaryKey(id int) (result WkbCustomerServiceGroup, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("id = ?", id).Find(&result).Error

	return
}
